//
//  CYBettingCell.m
//  CaiYun
//
//  Created by 今日信息科技 on 2017/7/15.
//  Copyright © 2017年 今日信息科技. All rights reserved.
//

#import "CYBettingCell.h"
#define map AL(10)
#define viewHeight AL(32)
@interface CYBettingCell(){
    CGFloat leftWidth;
}
@property (nonatomic, strong) CYLabel *left_titleLBL;
@property (nonatomic, strong) CYView *bottom_line;
@property (nonatomic, strong) CYView *weiji_backview;//万位/千位/百位/十位/个位 背景图
@property (nonatomic, strong) CYView *play_backview;//全/大／小/单／双/清/背景图
@property (nonatomic, strong) CAShapeLayer *shapeLayer;//虚线
@property (nonatomic, strong) NSMutableSet *selectNumberSet;  //选中的号码集合
@property (nonatomic, assign) CGFloat offsetX;// 号码按钮距cell左边的距离
@property (nonatomic, assign) BOOL isNumber;//如果是纯数字，或者长度小于2的汉字字符串，则为yes；否则为no
@end
@implementation CYBettingCell
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        self.selectionStyle = UITableViewCellSelectionStyleNone;
        CGSize size = [@"万" sizeWithAttributes:@{NSFontAttributeName :[UIFont systemFontOfSize:AL(PT(30))]}];
        leftWidth = ceil(size.width) + map * 2;//距离左边的宽度
        self.bottom_line.hidden = NO;
        
    }
    return self;
}
- (CYView *)bottom_line{
    if (!_bottom_line) {
        _bottom_line = [[CYView alloc]initWithColor:ColorHex(0xa9bed1)];
        [self addSubview:_bottom_line];
        
        [_bottom_line mas_makeConstraints:^(MASConstraintMaker *make) {
            make.bottom.equalTo(self.mas_bottom);
            make.left.equalTo(self).with.offset(leftWidth);
            make.right.equalTo(self.mas_right).with.offset(- map);
            make.height.mas_equalTo(0.5);
        }];
    }
    return _bottom_line;
}

- (CYLabel *)left_titleLBL{
    if (!_left_titleLBL) {
        _left_titleLBL = [[CYLabel alloc]initWithText:_left_title size:AL(PT(30)) textcolor:ColorHex(0x888888)];
        _left_titleLBL.numberOfLines = 0;
        [self addSubview:_left_titleLBL];
        
        [_left_titleLBL mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerY.equalTo(self);
            make.left.equalTo(self).with.offset(map);
            make.size.mas_equalTo([_left_titleLBL autoSizeWithWidth:_left_titleLBL.bounds.size.width / 2.0]);
        }];
    }
    return _left_titleLBL;
}



- (CYView *)weiji_backview{
    if (!_weiji_backview) {
        _weiji_backview = [[CYView alloc]initWithColor:nil];
        _weiji_backview.bounds = CGRectMake(0.0, 0.0, SCREEN_WIDTH, viewHeight + map * 2);
        [self addSubview:_weiji_backview];
        [self setupWeiJiBtn];//加载位级视图
        
        [_weiji_backview mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(self);
            make.centerX.equalTo(self);
            make.size.mas_equalTo(_weiji_backview.bounds.size);
        }];
    }
    return _weiji_backview;
}

- (CYView *)play_backview{
    if (!_play_backview) {
        _play_backview = [[CYView alloc]initWithColor:nil];
        _play_backview.bounds = CGRectMake(0.0, 0.0, SCREEN_WIDTH - leftWidth - map, viewHeight);
        [self addSubview:_play_backview];
        [self setupSubPlayBtn];
        
        [_play_backview mas_makeConstraints:^(MASConstraintMaker *make) {
            if (_selectWeiJi)//有位级选择
                make.top.equalTo(_weiji_backview.mas_bottom);
            else//没有位级选择
                make.top.equalTo(self).with.offset(map);
            make.left.equalTo(self).with.offset(leftWidth);
            make.size.mas_equalTo(_play_backview.bounds.size);
        }];
    }
    return _play_backview;
}

- (NSMutableSet *)selectNumberSet{
    if (!_selectNumberSet)
        _selectNumberSet = [NSMutableSet set];
    return _selectNumberSet;
}

- (NSMutableArray *)selectWeiJiArr{
    if (!_selectWeiJiArr)
        _selectWeiJiArr = [NSMutableArray array];
    return _selectWeiJiArr;
}
//- (void)setSelectNumberSet:(NSMutableSet *)selectNumberSet{
//    if (_selectNumberSet != selectNumberSet)
//        _selectNumberSet  = selectNumberSet;
//    [self setupStateForRandomNum];
//
//}
- (CAShapeLayer *)shapeLayer{
    if (!_shapeLayer)
        _shapeLayer = [CAShapeLayer layer];
    return _shapeLayer;
}

- (void)setLeft_title:(NSString *)left_title{
    if (_left_title != left_title){
        _left_title = left_title;
        self.left_titleLBL.text = _left_title;
        [self updateLeftTitleLBLBounds];
    }
    
}

- (void)setNumberArr:(NSArray *)numberArr{
    if (_numberArr != numberArr){
        _numberArr = numberArr;
        
        [self clear];//清除所有状态，视图
        [self judgeIsNumber];//判断号码是不是数字
        self.play_backview.hidden = NO;//如果位级选择为YES，则不显示玩法选择按钮
        [self setupSubNumberBtn];//加载号码按钮
        [self drawDottedLine];//画虚线
    }
}

- (void)setRandomNum:(NSArray *)randomNum{
    if (_randomNum != randomNum){
        _randomNum = randomNum;
        [self setWithArray];
        [self setupStateForRandomNum];
    }
}

- (void)setSelectWeiJi:(BOOL)selectWeiJi{
    if (_selectWeiJi != selectWeiJi)
        _selectWeiJi = selectWeiJi;
    if (selectWeiJi)
        self.weiji_backview.hidden = NO;//如果显示位级选择位YES,则初始化位级选择按钮的背景视图，并初始化位级选择按钮
    else {
        [_weiji_backview removeFromSuperview];
        _weiji_backview  = nil;
    }
}

//随机数组转换成选中的号码
- (void)setWithArray{
    
    [self.selectNumberSet removeAllObjects];
    [self.selectWeiJiArr  removeAllObjects];
    if (!_selectWeiJi)//没有位级的随机数组赋值
        for (int i = 0; i < _randomNum.count; i ++) {
            CYButton *button = [self viewWithTag:300 + [_randomNum[i] intValue]];
            if (button)
                [self.selectNumberSet addObject:[button titleForState:UIControlStateNormal]];
            else
                [self.selectNumberSet addObject:_randomNum[i]]; //比如快三-三同单选，号码为111,随机出来的数组为111，就不能直接使用下标获取按钮，而要直接只用随机数组里的号码
        }
    else{
        NSArray *selectNumberArr = [[[_randomNum[0] allValues] firstObject] allObjects];
        for (int i = 0; i < selectNumberArr.count; i ++) {//提取选中的随机号码
            NSString *string = [NSString stringWithFormat:@"%@",selectNumberArr[i]];
            [self.selectNumberSet addObject:string];
        }
        for (NSDictionary *dict in _randomNum) {
            NSString *string = [NSString stringWithFormat:@"%@",[[dict allKeys] firstObject]];
            if (![self.selectWeiJiArr containsObject:string])
                [self.selectWeiJiArr addObject:string];//提取选中的随机位级
        }
    }
}

- (void)updateLeftTitleLBLBounds{
    
    CGSize size = [@"万" sizeWithAttributes:@{NSFontAttributeName :_left_titleLBL.font}];
    [_left_titleLBL mas_updateConstraints:^(MASConstraintMaker *make) {
        make.size.mas_equalTo(CGSizeMake(ceil(size.width), ceil(size.height) * _left_title.length));
    }];
    
}

//根据号码数组，抽取任意位置的元素，判断是不是纯数字，或者长度小于2的汉字
- (void)judgeIsNumber{
    
    NSString *string = (_numberArr.count > 1 )?_numberArr[_numberArr.count / 2]:_numberArr[0];//如果数组的元素不止1个，则选取数组任意的元素(中间位置元素)，如果数组元素只有1个,则选取默认第一个元素
    _isNumber = ([NSString judgeInputIsNumber:string])?YES:NO;//判断是不是数字，或者少于2的汉字
    
}

//万位/千位/百位/十位/个位
- (void)setupWeiJiBtn{
    NSArray *array = @[@"万位",@"千位",@"百位",@"十位",@"个位"];
    CGFloat width = (SCREEN_WIDTH - _offsetX * 6) / 5.0;
    for (int i = 0; i < array.count; i++) {
        CYButton * button= [[CYButton alloc]initWithTitle:array[i] titleColor:ColorHex(0x888888) titleSize:AL(PT(30)) Image:@"gray"];
        [button addTarget:self action:@selector(actionForWeiJiBtn:) forControlEvents:UIControlEventTouchUpInside];
        [button setImage:[UIImage imageNamed:@"check"] forState:UIControlStateSelected];
        button.titleEdgeInsets = UIEdgeInsetsZero;
        button.imageEdgeInsets = UIEdgeInsetsZero;
        button.tag = 400 + i;
        [_weiji_backview addSubview:button];
        
        [button mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerY.equalTo(_weiji_backview);
            make.left.equalTo(_weiji_backview).with.offset(_offsetX + (width + _offsetX) * i);
            make.size.mas_equalTo(CGSizeMake(width, _weiji_backview.bounds.size.height - 2 * map));
        }];
        
    }
    //默认的位级选中状态
    for (int i = 0; i < _selectWeiJiArr.count; i ++) {
        NSUInteger tag = 400 + [_selectWeiJiArr[i] integerValue];
        CYButton *button = [_weiji_backview viewWithTag:tag];
        button.selected = YES;
    }
}

//玩法选择
- (void)setupSubPlayBtn{
    NSArray *array = (_isNumber)?@[@"全",@"大",@"小",@"单",@"双",@"清"]:@[];
    CGFloat leftInset = (_play_backview.bounds.size.width - array.count * viewHeight) / (array.count + 1);//获取每个玩法按钮之间的间距
    for (int i = 0; i < array.count; i ++) {
        CYButton *playBtn = [[CYButton alloc]initWithTitle:array[i] titleColor:ColorHex(0xa9bed1) backgroundColor:[UIColor clearColor] cornerRadius:AL(PT(64)) / 2.0];
        [playBtn addTarget:self action:@selector(actionForPlayBtn:) forControlEvents:UIControlEventTouchUpInside];
        playBtn.tag = (_isNumber)?(200 + i):(200 + 5);//清除按钮，tag标固定为205，所以如果只有一个按钮(清除按钮)，则直接让其tag为205
        if (i < 5)
            [playBtn setTitleColor:ORANGE_COLOR forState:UIControlStateSelected];//选中状态字体颜色
        else
            [playBtn setTitleColor:ColorHex(0XFF5B05) forState:UIControlStateHighlighted];
        [_play_backview addSubview:playBtn];
        
        [playBtn mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerY.equalTo(_play_backview);
            make.size.mas_equalTo(CGSizeMake(viewHeight, viewHeight));
            make.left.equalTo(_play_backview).with.offset(leftInset + (viewHeight + leftInset) * i);
        }];
    }
}

//号码选择按钮
- (void)setupSubNumberBtn{
    
    NSString *string = (_numberArr.count > 1 )?_numberArr[_numberArr.count / 2]:_numberArr[0];//如果数组的元素不止1个，则选取数组任意的元素(中间位置元素)，如果数组元素只有1个,则选取默认第一个元素
    
    CGFloat widtn_btn = (_isNumber || string.length == 1 || (string.length == 2 && _isNumber))?viewHeight:(string.length < 3)?viewHeight*1.5:viewHeight*3;//按钮的宽度 string.length==1即号码为大小单双的时候
    //    CGFloat offsetY = (_selectWeiJi)?(_offsetX + CGRectGetHeight(_weiji_backview.bounds)):(_offsetX * 2 + height_btn);//到父视图顶部的距离
    CGFloat radius = (_isNumber || string.length == 1 || (string.length == 2 && _isNumber))?widtn_btn / 2.0:AL(5.0);//半径
    //    NSUInteger firstNumber = ([NSString judgeInputIsNumber:_numberArr[0]] && [_numberArr[0] length] <= 2)?[_numberArr[0] integerValue]:0;//获取数组中，第一个号码的值,三目运算，数组第一个值为数字，且长度为1
    
    NSUInteger count = (_numberArr.count >= 6)?6:_numberArr.count;
    CGFloat leftInset = (_play_backview.bounds.size.width - count * widtn_btn) / (count + 1);
    for (int i = 0; i < _numberArr.count; i ++) {
        CGFloat row = (CGFloat)ceil(i / 6);//行
        CGFloat column = (_isNumber || string.length == 1)?((i <= 5)?i:(i % 6)):((i <= 2)?i:(i % 3));//列
        CYButton *numberBtn = [[CYButton alloc]initWithTitle:_numberArr[i] titleColor:THEME_COLOR backgroundColor:[UIColor clearColor] cornerRadius:radius];
        [numberBtn addTarget:self action:@selector(actionForNumberBtn:) forControlEvents:UIControlEventTouchUpInside];
        numberBtn .titleLabel.font = (string.length > 2)?[UIFont systemFontOfSize:AL(14)]:[UIFont systemFontOfSize:AL(17)];
        [numberBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateSelected];
        [numberBtn setBackgroundColor:THEME_COLOR forstate:UIControlStateSelected];
        [numberBtn setBackgroundColor:[UIColor clearColor] forstate:UIControlStateNormal];
        numberBtn.layer.borderColor = ColorHex(0x888888).CGColor;
        numberBtn.layer.borderWidth = 0.5;
        numberBtn.tag = (!_isNumber || [_numberArr[i] integerValue] > 100)?(300 + i):(300 + [_numberArr[i] intValue]);//因为有的号码是从1或者3开始，所以tag最好取数组中的号码，以便于随机选择时，能根据随机数选择下表，从而让相应的号码按钮变化
        [self addSubview:numberBtn];
        
        [numberBtn mas_makeConstraints:^(MASConstraintMaker *make) {
            if (_isNumber)
                make.top.equalTo(_play_backview.mas_bottom).with.offset(map + (viewHeight + map) * row);
            else
                make.centerY.equalTo(self);
            make.size.mas_equalTo(CGSizeMake(widtn_btn, viewHeight));
            make.left.equalTo(_play_backview).with.offset(leftInset + (widtn_btn + leftInset) * column);
        }];
    }
    
}
//机选选中的号码，显示红色
- (void)setupStateForRandomNum{
    NSMutableArray *mutableArr = [NSMutableArray array];
    [mutableArr addObjectsFromArray:[self subviews]];
    [mutableArr addObjectsFromArray:[_play_backview subviews]];
    [mutableArr addObjectsFromArray:[_weiji_backview subviews]];
    for (int i = 0; i < mutableArr.count; i ++) {
        CYButton *subBtn = mutableArr[i];
        if (subBtn.tag >= 200 && subBtn.tag < 500) {
            subBtn.selected = NO;
            subBtn.layer.borderColor = (subBtn.tag >= 200 && subBtn.tag < 400)?ColorHex(0x888888).CGColor:subBtn.layer.borderColor;
        }
    }
    
    //显示选中的随机号码
    if (_selectWeiJi)
        for (NSString *number in [self.selectNumberSet allObjects]) {
            NSUInteger tag = 300 + [number integerValue];
            CYButton *button = [self viewWithTag:tag];
            button.selected = YES;
            button.layer.borderColor = [UIColor clearColor].CGColor;
        }
    else
        for (int i = 0 ; i < _randomNum.count; i ++) {
            NSUInteger tag = 300 + [_randomNum[i] integerValue];
            int number = [[_randomNum[i] substringToIndex:1] intValue];
            CYButton *button = ([self viewWithTag:tag])?[self viewWithTag:tag]:[self viewWithTag:300 - 1 + number];//快三系列-三同单选的号码为111,取第一个位按钮的下标
            button.selected = YES;
            button.layer.borderColor = [UIColor clearColor].CGColor;
        }
    //显示选中的随机位级按钮
    if (_selectWeiJi)
        for (int i = 0; i < _selectWeiJiArr.count; i ++) {
            NSUInteger tag = 400 + [_selectWeiJiArr[i] integerValue];
            CYButton *button = [_weiji_backview viewWithTag:tag];
            button.selected = YES;
        }
    
}

//玩法按钮方法
- (void)actionForPlayBtn:(CYButton *)sender{
    sender.selected = YES;
    for (int i = 0 ; i < 6; i++) {
        CYButton *button = [self viewWithTag:200 + i];
        if (button.tag != sender.tag)
            button.selected = NO;
    }
    [self selectNumberBtn:sender.tag - 200];
    [self sendBlock];
}

//数字按钮方法
- (void)actionForNumberBtn:(CYButton *)sender{
    
    sender.selected = !sender.selected;
    sender.layer.borderColor = (sender.selected)?[UIColor clearColor].CGColor:ColorHex(0x888888).CGColor;
    if (sender.selected)
        [self.selectNumberSet addObject:[sender titleForState:UIControlStateNormal]];//选中按钮，以按钮的title为集合的元素
    else{
        if ([_selectNumberSet containsObject:[sender titleForState:UIControlStateNormal]])
            [_selectNumberSet removeObject:[sender titleForState:UIControlStateNormal]];//未选中按钮，从集合中删除该按钮的title
    }
    
    if (!_selectWeiJi)//位级选择不显示，则执行以下block ，title值为left_title
        _selectBlock(_left_title, _selectNumberSet);
    else{//位级选择显示，则筛选位级选择按钮，并执行block，title值为位级按钮的title
        NSArray *subviews = [_weiji_backview subviews];
        for (int i = 0 ; i < subviews.count; i ++) {
            CYButton *button = subviews[i];
            if (button.tag >= 400 && button.selected) //筛选选中状态的位级选择按钮
                _selectBlock([NSString stringWithFormat:@"%lu",button.tag - 400],_selectNumberSet);
        }
    }
    
}

//万/千/百/十/个位级选择
- (void)actionForWeiJiBtn:(CYButton *)sender{
    sender.selected = !sender.selected;
    NSMutableSet *set = [NSMutableSet setWithSet:_selectNumberSet];
    
    NSString *senderTagStr = [NSString stringWithFormat:@"%lu",sender.tag - 400];
    if (sender.selected){
        [self.selectWeiJiArr addObject:senderTagStr];
        _selectBlock(senderTagStr, set);
    }
    else{
        [self.selectWeiJiArr removeObject:senderTagStr];
        _selectBlock(senderTagStr, nil);
    }
}

//通过玩法按钮，自动选中号码 array为相应玩法下的数字数组
- (void)selectNumberBtn:(NSUInteger)index{
//    NSUInteger firstNumber = ([NSString judgeInputIsNumber:_numberArr[0]] && [_numberArr[0] length] <= 2)?[_numberArr[0] integerValue]:0;//获取数组中，第一个号码的值,三目运算，数组第一个值为数字，且长度为1
    NSUInteger midNum = floor(_numberArr.count / 2.0 );
    id num = _numberArr[midNum];
    CYButton *midBtn = ([NSString judgeInputIsNumber:num])?[self viewWithTag:300 + [num intValue]]:[self viewWithTag:300 + midNum];//中间的按钮
    for (CYView *view in [self subviews]) {
        if ([view isKindOfClass:[CYButton class]] && view.tag >= 300) {
            CYButton *button = (CYButton *)view;
            if (index == 0) {//全
                button.selected = YES;
                button.layer.borderColor = [UIColor clearColor].CGColor;
            }
            else if (index == 1){//大
                button.selected = (button.tag >= midBtn.tag)?YES:NO;
                button.layer.borderColor = (button.selected)?[UIColor clearColor].CGColor:ColorHex(0x888888).CGColor;
            }
            else if (index == 2){//小
                button.selected = (button.tag < midBtn.tag)?YES:NO;
                button.layer.borderColor = (button.selected)?[UIColor clearColor].CGColor:ColorHex(0x888888).CGColor;
            }
            else if (index == 3){//单
                button.selected = ([[button titleForState:UIControlStateNormal] integerValue] % 2)?YES:NO;
                button.layer.borderColor = (button.tag % 2)?[UIColor clearColor].CGColor:ColorHex(0x888888).CGColor;
            }
            else if (index == 4){//双
                button.selected = ([[button titleForState:UIControlStateNormal] integerValue] % 2)?NO:YES;
                button.layer.borderColor = (button.tag % 2)?ColorHex(0x888888).CGColor:[UIColor clearColor].CGColor;
            }
            else{//清
                button.selected = NO;
                button.layer.borderColor = ColorHex(0x888888).CGColor;
            }
            
            if (button.selected)
                [self.selectNumberSet addObject:[button titleForState:UIControlStateNormal]];
            else
                [self.selectNumberSet removeObject:[button titleForState:UIControlStateNormal]];
        }
    }
    
}

- (void)sendBlock{
    if (!_selectWeiJi)
        _selectBlock(_left_title, _selectNumberSet);
    else
        for (NSString *weijiStr in self.selectWeiJiArr) {
            _selectBlock(weijiStr, _selectNumberSet);
        }
}
//画虚线
- (void)drawDottedLine{
    [_shapeLayer removeFromSuperlayer];
    _shapeLayer = nil;
    
    NSUInteger row = ceil([_numberArr count] / 6.0);
    CGFloat cell_height = PT(52 + 64 * row + 24 * row + 44 + 40 + CGRectGetHeight(_weiji_backview.bounds));
        DeLog(@"row  %lu  cell_height  %f",(unsigned long)row,cell_height);
    [self.shapeLayer setBounds:CGRectMake(0.0, 0.0, SCREEN_WIDTH,  cell_height)];
    [self.shapeLayer setPosition:CGPointMake(SCREEN_WIDTH / 2, cell_height / 2)];
    [self.shapeLayer setFillColor:[UIColor clearColor].CGColor];
    //  设置虚线颜色为blackColor
    [self.shapeLayer setStrokeColor:ColorHex(0xa9bed1).CGColor];
    //  设置虚线宽度
    [self.shapeLayer setLineWidth:1];
    [self.shapeLayer setLineJoin:kCALineJoinRound];
    //  设置线宽，线间距
    [self.shapeLayer setLineDashPattern:[NSArray arrayWithObjects:[NSNumber numberWithInt:AL(3)], [NSNumber numberWithInt:AL(2)], nil]];
    //  设置路径
    CGMutablePathRef path = CGPathCreateMutable();
    CGPathMoveToPoint(path, NULL, 14 + 20, 22);
    CGPathAddLineToPoint(path, NULL,14 + 20, cell_height - 26);
    [self.shapeLayer setPath:path];
    CGPathRelease(path);
    //  把绘制好的虚线添加上来
    [self.layer addSublayer:self.shapeLayer];
}

- (void)clear{
    for (CYView *view in [self subviews]) {
        if ([view isKindOfClass:[CYButton class]] && view.tag >= 200){
            [view removeFromSuperview];
        }
    }
    
    if (_selectWeiJi == NO) {
        [self.selectWeiJiArr removeAllObjects];//清除选中的位级数组
        for (CYButton *button in [_weiji_backview subviews]) {
            if (button.tag >= 400)
                [button removeFromSuperview];
        }
        _weiji_backview = nil;
    }
    else{
        for (int i = 0; i < 5; i++) {//先复原所有按钮为选中状态
            CYButton *button = [_weiji_backview viewWithTag:400 + i];
            button.selected = NO;
        }
        
        for (int i = 0; i < _selectWeiJiArr.count; i ++) {//根据选中位级数组，设置选中的位级按钮
            NSUInteger tag = 400 + [_selectWeiJiArr[i] integerValue];
            CYButton *button = [_weiji_backview viewWithTag:tag];
            button.selected = YES;
        }
    }
    
    [self.selectNumberSet removeAllObjects]; //清楚选中的号码集合
    [_play_backview removeFromSuperview];//
    _play_backview = nil;
}


- (void)setAnotherSelectArr:(NSArray *)anotherSelectArr{
    if (_anotherSelectArr != anotherSelectArr) {
        _anotherSelectArr = anotherSelectArr;
        
        for (NSString *anotherNum in _anotherSelectArr) {
            for (NSString * selectNum in [_selectNumberSet allObjects]) {
                if ([anotherNum containsString:selectNum] || [selectNum containsString:anotherNum]) {
                    CYButton *button = [self viewWithTag:300 + [selectNum intValue]];
                    [self performSelector:@selector(actionForNumberBtn:) withObject:button];
                }
            }
            
        }
    }
    
}
- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];
    
    // Configure the view for the selected state
}

@end
